package com.theobserver.theobserver;

import android.content.Context;
import android.net.wifi.aware.PublishConfig;
import android.os.ParcelUuid;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.avos.avoscloud.AVObject;

import java.util.ArrayList;
import java.util.zip.Inflater;

/**
 * Created by wssxk on 7/7/17.
 */

public class MainPageHotNewsPageAdapter extends FragmentPagerAdapter {

    Context mContext = null;
    //ArrayList<MainPageNewsListFragment> pages = null;       //所有分类页面
    ArrayList<AVObject> catalog = null;

    public MainPageHotNewsPageAdapter(FragmentManager fm)
    {
        super(fm);
    }

    public void init(Context context)
    {
        mContext = context;
        //pages = new ArrayList<>();
        catalog = new ArrayList<>();
    }

    public int getCount()
    {
        return catalog.size();
    }

    public Fragment getItem(int pos)
    {
        //MainPageNewsListFragment mFragment = new MainPageNewsListFragment();
        //mFragment.init(mContext);
        //return mFragment;
        //return pages.get(pos);
        MainPageNewsListFragment mFragment = new MainPageNewsListFragment();
        mFragment.setCatalog(catalog.get(pos));
        mFragment.init(mContext);
        return mFragment;
    }

    public CharSequence getPageTitle(int pos)
    {
        /*
        switch (pos)
        {
            case 0:
                return "推荐";
                //break;
            case 1:
                return "时政";
            case 2:
                return "科技";
            case 3:
                return "母婴";
            case 4:
                return "娱乐";
            case 5:
                return "游戏";
            default:
                return "Tab"+pos;

        }
        */
        //return pages.get(pos).catalog.getString("catalog_name");
        return catalog.get(pos).getString("catalog_name");
    }

    public void setCatalog(ArrayList<AVObject> ca)
    {
        catalog.clear();
        catalog.addAll(ca);
        //notifyDataSetChanged();
    }

}
